<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-productDetail-edit" th:object="${productDetail}" enctype="multipart/form-data">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
            <div class="form-group">	
                <label class="col-sm-3 control-label">产品溯源码：</label>
                <div class="col-sm-8">
                    <input id="productCode" name="productCode" th:field="*{productCode}" class="form-control" readonly="true" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">流程类型：</label>
                <div class="col-sm-8">
                    <input id="processType1" name="processType1" th:field="*{processType}" class="form-control"  type="hidden">
                    <select id="processType" class="form-control m-b" th:with="type=${@dict.getType('gh_process_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{processType}"></option>
	                </select>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">操作说明：</label>
                <div class="col-sm-8">
                    <input id="descInfo" name="descInfo" th:field="*{descInfo}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">操作人：</label>
                <div class="col-sm-8">
                    <input id="opeUser" name="opeUser" th:field="*{opeUser}" class="form-control" type="text">
                </div>
            </div>
        <!--     <div class="form-group">	
                <label class="col-sm-3 control-label">操作时间：</label>
                <div class="col-sm-8">
                    <input id="opeTime" name="opeTime" th:field="*{opeTime}" class="form-control" type="text">
                </div>
            </div> -->
            <div class="form-group">	
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input id="remarks" name="remarks" th:field="*{remarks}" class="form-control" type="text">
                </div>
            </div>
            
            <div class="form-group">	
			   <label class="col-sm-3 control-label">图片1：</label>
				<div class="col-sm-8">
			     <img id="image1" name="image1" value='custom' alt=" "  data-address='' height="150" width="150" th:src="(${productDetail.image1} == '') ? @{/img/profile.jpg} : @{/profile/avatar/} + ${productDetail.image1}"/>
			     <input type="file" id="chooseImage1" name="file1" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片2：</label>
				<div class="col-sm-8">
			     <img id="image2" name="image2" value='custom' alt=" " data-address='' height="150" width="150" th:src="(${productDetail.image2} == '') ? @{/img/profile.jpg} : @{/profile/avatar/} + ${productDetail.image2}"/>
			     <input type="file" id="chooseImage2" name="file2" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片3：</label>
				<div class="col-sm-8">
			     <img id="image3" name="image3" value='custom' alt=" " data-address='' height="150" width="150" th:src="(${productDetail.image3} == '') ? @{/img/profile.jpg} : @{/profile/avatar/} + ${productDetail.image3}"/>
			     <input type="file" id="chooseImage3" name="file3" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片4：</label>
				<div class="col-sm-8">
			     <img id="image4" name="image4" value='custom' alt=" " data-address='' height="150" width="150" th:src="(${productDetail.image4} == '') ? @{/img/profile.jpg} : @{/profile/avatar/} + ${productDetail.image4}"/>
			     <input type="file" id="chooseImage4" name="file4" >
                 </div>
            </div>
            	<div class="form-group">	
			   <label class="col-sm-3 control-label">图片5：</label>
				<div class="col-sm-8">
			     <img id="image5" name="image5" value='custom' alt=" " data-address='' height="150" width="150" th:src="(${productDetail.image5} == '') ? @{/img/profile.jpg} : @{/profile/avatar/} + ${productDetail.image5}"/>
			     <input type="file" id="chooseImage5" name="file5" >
                 </div>
            </div>
            
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "module/productDetail"
		$("#form-productDetail-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	          /*   $.operate.save(prefix + "/add", $('#form-productDetail-add').serialize()); */
	        }
	    } 
		
		function add(){
			console.log("start upload pic");
			if(!checkProcessType()){
			    var prefix = ctx + "module/productDetail";
			    var form = new FormData(document.getElementById("form-productDetail-edit"));
			    $.ajax({  
			        type : 'POST',  
			        url : prefix+"/edit",  
			        data: form,
			        processData:false,
	                contentType:false,
			        success : function(result) {  
			        	console.log(result);
			        	if(result.code=='0'){
			        		/* console.log("导入成功了") */
			        		$.operate.saveSuccess(result);
			        	}else{
			        		$.modal.alertError("错误提示："+result.msg);
			        	
			        	}
			        },  
			        error : function() {  
			        	$.modal.alertError("错误提示：上传失败，请检查网络后重试,上传文件太大");
		
			        }  
			    });
			}
		}
		
		$('#chooseImage1').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image1")[0].src;  
	    	$('#image1').attr('src',src);   	
	     });
		$('#chooseImage2').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath2 = $("#image2")[0].src;  
	    	$('#image2').attr('src',src);   	
	     });

		$('#chooseImage3').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image3")[0].src;  
	    	$('#image3').attr('src',src);   	
	     });

		$('#chooseImage4').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image4")[0].src;  
	    	$('#image4').attr('src',src);   	
	     });

		$('#chooseImage5').on('change',function(){
	    	var filePath = $(this).val(),         //获取到input的value，里面是文件的路径
	    		fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
	    		src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
	    		
	    	// 检查是否是图片
	    	if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {
	    		error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');
	        	return;  
	        }
	        console.log("五张图片来处理吧");
	    	var imagePath1 = $("#image5")[0].src;  
	    	$('#image5').attr('src',src);   	
	     });
		
		function checkProcessType(){
			var flag = false;
			var productCode = $("#productCode").val();
			var oldProcessType = $("#processType1").val();
			var newProcessType = $("#processType").val();
			var processTyeName = $("#processType").find("option:selected").text();
			if(oldProcessType != newProcessType){
			   $.ajax({  
			        type : 'POST',  
			        url : prefix+"/checkProcessType",  
			        data: {"productCode":productCode,"processType":newProcessType},
			        dataType:"json",
			        async : false,
			        success : function(result) {
			        	if(result == 1){
			        		flag = true;
			        		 layer.open({
			        			  title: '提示信息',
			        			  content: "已添加过"+processTyeName+"流程！",
			        			  icon:0
			        			});  
			        	}
			        },   
			    });
			}
			   return flag;
		}
	</script>
</body>
</html>
